<!DOCTYPE HTML>
<html>
<head>
    <title><%= __('views.addStore')%></title>
    <% include common/meta.ejs %>
    <% include common/public.ejs %>
</head>

<body>

<form class="edit-form">
    <input type="hidden" name="id" value="<%= data.info.id %>">
    <div class="weui_cells weui_cells_form">
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label"><%= __('views.storeName')%></label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" placeholder="<%= __('views.inputName')%>" name="name" value="<%= data.info.name %>">
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label"><%= __('views.storeCode')%></label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" placeholder="<%= __('views.inputCodes')%>" name="code" value="<%= data.info.code %>">
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label"><%= __('views.storeType')%></label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <select class="weui_select" emptyOption="false" style="height: 24px;line-height: 24px;padding-left: 0;"
                        options="shopType" id="shopType" name="shopType">
                    <% if(data && data.shopType) {for(var i = 0;i < data.shopType.length;i++) { %>
                    <option value="<%= data.shopType[i].code %>" <%= data.info.shopType==data.shopType[i].code?'selected':''%>><%= data.shopType[i].name %></option>
                    <% }} %>
                </select>
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label"><%= __('views.superior')%></label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <select class="weui_select"
                        style="height: 24px;line-height: 24px;padding-left: 0;"
                        name="parent.id">
                    <% if(data && data.userParent) { for(i = 0;i < data.userParent.length;i++) { %>
                    <option value="<%= data.userParent[i].id %>" <%= data.info.parentId==data.userParent[i].id %>><%= data.userParent[i].name %></option>
                    <% } } %>
                </select>
            </div>
        </div>
        <div class="weui_cell weui_cell_switch">
            <div class="weui_cell_hd"><label class="weui_label"><%= __('views.address')%></label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" name="pc" placeholder="<%= __('views.pleaseSelect')%>" id='city-picker' dol-validate="required" value="<%= data.info.province?data.info.province+' '+data.info.city:'' %>" />
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label"><%= __('views.street')%></label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" name="address" placeholder="<%= __('views.detailedAddress')%>" value="<%= data.info.address %>">
            </div>
        </div>

        <div class="weui_cell">
            <div class="weui_cell_hd"><label for="" class="weui_label"><%= __('views.timezone')%></label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" id='timeZone' name="timeZone" placeholder="<%= __('views.pleaseSelect')%>" value="<%= data.info.address || 'UTC+8' %>" />
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label for="" class="weui_label"><%= __('views.openingStore')%></label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" id='startDate' name="openTime" placeholder="<%= __('views.pleaseInput')%>" value="<%= data.info.openTime || '10:00' %>"/>
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label for="" class="weui_label"><%= __('views.closingStore')%></label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" id='endDate' name="closeTime" placeholder="<%= __('views.pleaseInput')%>" value="<%= data.info.closeTime || '22:00' %>"/>
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label"><%= __('views.contactPerson')%></label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" name="contactPerson" placeholder="<%= __('views.pleaseInput')%>" value="<%= data.info.contactPerson %>">
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label"><%= __('views.telephone')%></label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" name="telephone" placeholder="<%= __('views.pleaseInput')%>" value="<%= data.info.telephone %>">
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label"><%= __('views.cellphoneNumber')%></label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" name="mobile" placeholder="<%= __('views.pleaseInput')%>" value="<%= data.info.mobile %>">
            </div>
        </div>
    </div>
    <div style="text-align: center;width: 75%;padding: 20px 0;margin: auto;">
        <a href="javascript:void(0);" class="weui_btn weui_btn_warn btn-submit"><%= __('views.save')%></a>
        <a href="myDianZ?openId=<%= session.openId %>" class="weui_btn weui_btn_default"><%= __('views.return')%></a>
    </div>

</form>
<% include common/footer.ejs %>
<script>
    "use strict";
    $(function () {
        Dolphin.enum.setOptions({
            ajaxFlag: true,
            enumUrl: '/api/5b8e27d5bb9547f48235bd70aea199b9@code={id}',
            cookieFlag: false
        });


        $("#city-picker").cityPicker({
            title: Dolphin.i18n.get("views.pleaseSelect"),
            showDistrict: false,
            toolbarCloseText:Dolphin.i18n.get("views.ok")
        });

        $("#timeZone").select({
            title: Dolphin.i18n.get("views.pleaseSelect"),
            closeText:Dolphin.i18n.get("views.ok"),
            items: [
                {title: "UTC-11", value: "UTC-11",},
                {title: "UTC-10", value: "UTC-10",},
                {title: "UTC-9", value: "UTC-9",},
                {title: "UTC-8", value: "UTC-8",},
                {title: "UTC-7", value: "UTC-7",},
                {title: "UTC-6", value: "UTC-6",},
                {title: "UTC-5", value: "UTC-5",},
                {title: "UTC-4", value: "UTC-4",},
                {title: "UTC-3", value: "UTC-3",},
                {title: "UTC-2", value: "UTC-2",},
                {title: "UTC+1", value: "UTC+1",},
                {title: "UTC+2", value: "UTC+2",},
                {title: "UTC+3", value: "UTC+3",},
                {title: "UTC+4", value: "UTC+4",},
                {title: "UTC+5", value: "UTC+5",},
                {title: "UTC+6", value: "UTC+6",},
                {title: "UTC+7", value: "UTC+7",},
                {title: "UTC+8", value: "UTC+8",},
                {title: "UTC+9", value: "UTC+9",},
                {title: "UTC+10", value: "UTC+10",},
                {title: "UTC+11", value: "UTC+11",}
            ]
        });

        $("#startDate").select({
            title: Dolphin.i18n.get("views.pleaseSelect"),
            closeText:Dolphin.i18n.get("views.ok"),
            items: [
                {title: "0:00", value: "0:00",},
                {title: "0:30", value: "0:30",},
                {title: "1:00", value: "1:00",},
                {title: "1:30", value: "1:30",},
                {title: "2:00", value: "2:00",},
                {title: "2:30", value: "2:30",},
                {title: "3:00", value: "3:00",},
                {title: "3:30", value: "3:30",},
                {title: "4:00", value: "4:00",},
                {title: "4:30", value: "4:30",},
                {title: "5:00", value: "5:00",},
                {title: "5:30", value: "5:30",},
                {title: "6:00", value: "6:00",},
                {title: "6:30", value: "6:30",},
                {title: "7:00", value: "7:00",},
                {title: "7:30", value: "7:30",},
                {title: "8:00", value: "8:00",},
                {title: "8:30", value: "8:30",},
                {title: "9:00", value: "9:00",},
                {title: "9:30", value: "9:30",},
                {title: "10:00", value: "10:00",},
                {title: "10:30", value: "10:30",},
                {title: "11:00", value: "11:00",},
                {title: "11:30", value: "11:30",},
                {title: "12:00", value: "12:00",},
                {title: "12:30", value: "12:30",},
                {title: "13:00", value: "13:00",},
                {title: "13:30", value: "13:30",},
                {title: "14:00", value: "14:00",},
                {title: "14:30", value: "14:30",},
                {title: "15:00", value: "15:00",},
                {title: "15:30", value: "15:30",},
                {title: "16:00", value: "16:00",},
                {title: "16:30", value: "16:30",},
                {title: "17:00", value: "17:00",},
                {title: "17:30", value: "17:30",},
                {title: "18:00", value: "18:00",},
                {title: "18:30", value: "18:30",},
                {title: "19:00", value: "19:00",},
                {title: "19:30", value: "19:30",},
                {title: "20:00", value: "20:00",},
                {title: "20:30", value: "20:30",}
            ]
        });

        $("#endDate").select({
            title: Dolphin.i18n.get("views.pleaseSelect"),
            closeText:Dolphin.i18n.get("views.ok"),
            items: [
                {title: "10:00", value: "10:00",},
                {title: "10:30", value: "10:30",},
                {title: "11:00", value: "11:00",},
                {title: "11:30", value: "11:30",},
                {title: "12:00", value: "12:00",},
                {title: "12:30", value: "12:30",},
                {title: "13:00", value: "13:00",},
                {title: "13:30", value: "13:30",},
                {title: "14:00", value: "14:00",},
                {title: "14:30", value: "14:30",},
                {title: "15:00", value: "15:00",},
                {title: "15:30", value: "15:30",},
                {title: "16:00", value: "16:00",},
                {title: "16:30", value: "16:30",},
                {title: "17:00", value: "17:00",},
                {title: "17:30", value: "17:30",},
                {title: "18:00", value: "18:00",},
                {title: "18:30", value: "18:30",},
                {title: "19:00", value: "19:00",},
                {title: "19:30", value: "19:30",},
                {title: "20:00", value: "20:00",},
                {title: "20:30", value: "20:30",},
                {title: "21:00", value: "21:00",},
                {title: "21:30", value: "21:30",},
                {title: "22:00", value: "22:00",},
                {title: "22:30", value: "22:30",},
                {title: "23:00", value: "23:00",},
                {title: "23:30", value: "23:30",},
                {title: "23:59", value: "23:59",}
            ]
        });

        $('.btn-submit').click(function () {
            var ef = $(".edit-form");
            if (Dolphin.form.validate(ef)) {
                let data = Dolphin.form.getValue(ef, '"');
                if (data.parent && !data.parent.id)
                    delete data.parent;
                data.category = data.category || '3';
                data.level = '4';

                var pcArray = data.pc.split(" ");
                data.province = pcArray[0];
                data.city = pcArray[1];
                console.log(data);
                Dolphin.ajax({
                    url: '<%= global.config.contextPath == '/' ? '' : global.config.contextPath %>/api/742445c653654caaa4a1fa69eb651a9a',
                    type: Dolphin.requestMethod.PUT,
                    forceUrl: true,
                    data: Dolphin.json2string(data),
                    onSuccess: function (reData) {
                        location.href = 'myDianZ';
                    }
                });

            }
        })
    })


</script>
</body>
</html>